"""
MCP Server 服务实现
PS：注释很重要，有助于帮助大模型理解函数的调用方式
"""
from fastmcp import FastMCP

mcp = FastMCP("MyMCP")


@mcp.tool
def multiply(a: float, b: float) -> float:
    """
    Multiplies two numbers.
    :param a: 第一个乘数
    :param b: 第二个乘数
    :return: 两数相乘的结果
    """
    return a * b


@mcp.tool
def get_weather(city: str) -> str:
    """
    Get temperature by city name.
    :param city: 城市
    :return: 城市的天气描述
    """
    return f"{city}今天天气晴，温度是20度"


# Static resource
@mcp.resource("config://version")
def get_version():
    return "2.0.1"


# Dynamic resource template
@mcp.resource("users://{user_id}/profile")
def get_profile(user_id: int):
    # Fetch profile for user_id...
    return {"name": f"User {user_id}", "status": "active"}


@mcp.prompt
def summarize_request(text: str) -> str:
    """Generate a prompt asking for a summary."""
    return f"Please summarize the following text:\n\n{text}"


if __name__ == '__main__':
    mcp.run(transport="stdio")  # run as a local script server
    # mcp.run(transport="streamable-http", host="127.0.0.1", port=8888)  # Run as a web server
    # mcp.run(transport="sse", host="127.0.0.1", port=8888)  # Run as a web server
